<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Compress::Raw::Zlib - Low-Level Interface to zlib compression library - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/Compress::Raw::Zlib">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Compress::Raw::Zlib.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/Compress::Raw::Zlib">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/Compress::Raw::Zlib">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/Compress::Raw::Zlib">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/Compress::Raw::Zlib">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/Compress::Raw::Zlib">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/Compress::Raw::Zlib">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/Compress::Raw::Zlib">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/Compress::Raw::Zlib">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/Compress::Raw::Zlib">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/Compress::Raw::Zlib">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/Compress::Raw::Zlib">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/Compress::Raw::Zlib">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/Compress::Raw::Zlib">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/Compress::Raw::Zlib">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/Compress::Raw::Zlib">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/Compress::Raw::Zlib">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/Compress::Raw::Zlib">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/Compress::Raw::Zlib">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/Compress::Raw::Zlib">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/Compress::Raw::Zlib">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/Compress::Raw::Zlib">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/Compress::Raw::Zlib">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/Compress::Raw::Zlib">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/Compress::Raw::Zlib">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/Compress::Raw::Zlib">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/Compress::Raw::Zlib">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/Compress::Raw::Zlib">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/Compress::Raw::Zlib">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/Compress::Raw::Zlib">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/Compress::Raw::Zlib">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/Compress::Raw::Zlib">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/Compress::Raw::Zlib">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/Compress::Raw::Zlib">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/Compress::Raw::Zlib">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/Compress::Raw::Zlib">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/Compress::Raw::Zlib">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/Compress::Raw::Zlib">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/Compress::Raw::Zlib">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/Compress::Raw::Zlib">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/Compress::Raw::Zlib">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/Compress::Raw::Zlib">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/Compress::Raw::Zlib">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/Compress::Raw::Zlib">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/Compress::Raw::Zlib">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/Compress::Raw::Zlib">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/Compress::Raw::Zlib">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/Compress::Raw::Zlib">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/Compress::Raw::Zlib">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/Compress::Raw::Zlib">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/Compress::Raw::Zlib">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/Compress::Raw::Zlib">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/Compress::Raw::Zlib">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/Compress::Raw::Zlib">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/Compress::Raw::Zlib">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/Compress::Raw::Zlib">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/Compress::Raw::Zlib">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/Compress::Raw::Zlib">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/Compress::Raw::Zlib">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/Compress::Raw::Zlib">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/Compress::Raw::Zlib">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/Compress::Raw::Zlib">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/Compress::Raw::Zlib">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/Compress::Raw::Zlib">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/Compress::Raw::Zlib">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/Compress::Raw::Zlib">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/Compress::Raw::Zlib">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/Compress::Raw::Zlib">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/Compress::Raw::Zlib">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/Compress::Raw::Zlib">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/Compress::Raw::Zlib">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/Compress::Raw::Zlib">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/Compress::Raw::Zlib">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/Compress::Raw::Zlib">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/Compress::Raw::Zlib">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/Compress::Raw::Zlib">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/Compress::Raw::Zlib">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/Compress::Raw::Zlib">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/Compress::Raw::Zlib">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/Compress::Raw::Zlib">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/Compress::Raw::Zlib">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Compress::Raw::Zlib.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/Compress::Raw::Zlib">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/Compress::Raw::Zlib">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/Compress::Raw::Zlib">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/Compress::Raw::Zlib">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/Compress::Raw::Zlib">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/Compress::Raw::Zlib">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/Compress::Raw::Zlib">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/Compress::Raw::Zlib">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/Compress::Raw::Zlib">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/Compress::Raw::Zlib">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/Compress::Raw::Zlib">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/Compress::Raw::Zlib">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/Compress::Raw::Zlib">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/Compress::Raw::Zlib">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/Compress::Raw::Zlib">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/Compress::Raw::Zlib">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/Compress::Raw::Zlib">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/Compress::Raw::Zlib">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/Compress::Raw::Zlib">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/Compress::Raw::Zlib">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/Compress::Raw::Zlib">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/Compress::Raw::Zlib">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/Compress::Raw::Zlib">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/Compress::Raw::Zlib">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/Compress::Raw::Zlib">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/Compress::Raw::Zlib">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/Compress::Raw::Zlib">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/Compress::Raw::Zlib">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/Compress::Raw::Zlib">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/Compress::Raw::Zlib">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/Compress::Raw::Zlib">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/Compress::Raw::Zlib">5.35.1</a>
          <a class="dropdown-item active" href="./Compress::Raw::Zlib.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./Compress::Raw::Zlib.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./Compress::Raw::Zlib.html">Compress::Raw::Zlib</a>
          <div id="more">
            (<a href="./Compress::Raw::Zlib.txt">source</a>,
            <a href="https://metacpan.org/pod/Compress::Raw::Zlib">CPAN</a>)
          </div>
            <div id="moduleversion">version 2.101</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Compress::Raw::Zlib::Deflate">Compress::Raw::Zlib::Deflate</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#($d,-$status)-=-new-Compress::Raw::Zlib::Deflate(-%5BOPT%5D-)">($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) </a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$d-%3Edeflate($input,-$output)">$status = $d-&gt;deflate($input, $output)</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$d-%3Eflush($output-%5B,-$flush_type%5D)">$status = $d-&gt;flush($output [, $flush_type]) </a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$d-%3EdeflateReset()">$status = $d-&gt;deflateReset() </a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$d-%3EdeflateParams(%5BOPT%5D)">$status = $d-&gt;deflateParams([OPT])</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$d-%3EdeflateTune($good_length,-$max_lazy,-$nice_length,-$max_chain)">$status = $d-&gt;deflateTune($good_length, $max_lazy, $nice_length, $max_chain)</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Edict_adler()">$d-&gt;dict_adler()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Ecrc32()">$d-&gt;crc32()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Eadler32()">$d-&gt;adler32()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Emsg()">$d-&gt;msg()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Etotal_in()">$d-&gt;total_in()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Etotal_out()">$d-&gt;total_out()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Eget_Strategy()">$d-&gt;get_Strategy()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Eget_Level()">$d-&gt;get_Level()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Eget_BufSize()">$d-&gt;get_BufSize()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Example">Example</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Compress::Raw::Zlib::Inflate">Compress::Raw::Zlib::Inflate</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#($i,-$status)-=-new-Compress::Raw::Zlib::Inflate(-%5BOPT%5D-)"> ($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) </a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$i-%3Einflate($input,-$output-%5B,$eof%5D)"> $status = $i-&gt;inflate($input, $output [,$eof]) </a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$i-%3EinflateSync($input)">$status = $i-&gt;inflateSync($input)</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$status-=-$i-%3EinflateReset()">$status = $i-&gt;inflateReset() </a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$i-%3Edict_adler()">$i-&gt;dict_adler()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$i-%3Ecrc32()">$i-&gt;crc32()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$i-%3Eadler32()">$i-&gt;adler32()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$i-%3Emsg()">$i-&gt;msg()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$i-%3Etotal_in()">$i-&gt;total_in()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$i-%3Etotal_out()">$i-&gt;total_out()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#$d-%3Eget_BufSize()1">$d-&gt;get_BufSize()</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Examples">Examples</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#CHECKSUM-FUNCTIONS">CHECKSUM FUNCTIONS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Misc">Misc</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#my-$version-=-Compress::Raw::Zlib::zlib_version();">my $version = Compress::Raw::Zlib::zlib_version();</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#my-$flags-=-Compress::Raw::Zlib::zlibCompileFlags();">my $flags = Compress::Raw::Zlib::zlibCompileFlags();</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#The-LimitOutput-option.">The LimitOutput option.</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#ACCESSING-ZIP-FILES">ACCESSING ZIP FILES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#FAQ">FAQ</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Compatibility-with-Unix-compress/uncompress.">Compatibility with Unix compress/uncompress.</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Accessing-.tar.Z-files">Accessing .tar.Z files</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#Zlib-Library-Version-Support">Zlib Library Version Support</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#CONSTANTS">CONSTANTS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#SUPPORT">SUPPORT</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#MODIFICATION-HISTORY">MODIFICATION HISTORY</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./Compress::Raw::Zlib.html#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./Compress::Raw::Zlib.html#NAME">#</a>NAME</h1>

<p>Compress::Raw::Zlib - Low-Level Interface to zlib compression library</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./Compress::Raw::Zlib.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use Compress::Raw::Zlib ;

($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) ;
$status = $d-&gt;deflate($input, $output) ;
$status = $d-&gt;flush($output [, $flush_type]) ;
$d-&gt;deflateReset() ;
$d-&gt;deflateParams(OPTS) ;
$d-&gt;deflateTune(OPTS) ;
$d-&gt;dict_adler() ;
$d-&gt;crc32() ;
$d-&gt;adler32() ;
$d-&gt;total_in() ;
$d-&gt;total_out() ;
$d-&gt;msg() ;
$d-&gt;get_Strategy();
$d-&gt;get_Level();
$d-&gt;get_BufSize();

($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) ;
$status = $i-&gt;inflate($input, $output [, $eof]) ;
$status = $i-&gt;inflateSync($input) ;
$i-&gt;inflateReset() ;
$i-&gt;dict_adler() ;
$d-&gt;crc32() ;
$d-&gt;adler32() ;
$i-&gt;total_in() ;
$i-&gt;total_out() ;
$i-&gt;msg() ;
$d-&gt;get_BufSize();

$crc = adler32($buffer [,$crc]) ;
$crc = crc32($buffer [,$crc]) ;

$crc = crc32_combine($crc1, $crc2, $len2);
$adler = adler32_combine($adler1, $adler2, $len2);

my $version = Compress::Raw::Zlib::zlib_version();
my $flags = Compress::Raw::Zlib::zlibCompileFlags();</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./Compress::Raw::Zlib.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>The <i>Compress::Raw::Zlib</i> module provides a Perl interface to the <i>zlib</i> compression library (see <a href="./Compress::Raw::Zlib.html#AUTHOR">&quot;AUTHOR&quot;</a> for details about where to get <i>zlib</i>).</p>

<h1 id="Compress::Raw::Zlib::Deflate"><a class="permalink" href="./Compress::Raw::Zlib.html#Compress::Raw::Zlib::Deflate">#</a><a id="Compress"></a>Compress::Raw::Zlib::Deflate</h1>

<p>This section defines an interface that allows in-memory compression using the <i>deflate</i> interface provided by zlib.</p>

<p>Here is a definition of the interface available:</p>

<h2 id="($d,-$status)-=-new-Compress::Raw::Zlib::Deflate(-[OPT]-)"><a class="permalink" href="./Compress::Raw::Zlib.html#($d,-$status)-=-new-Compress::Raw::Zlib::Deflate(-%5BOPT%5D-)">#</a><a id="d-status-new-Compress::Raw::Zlib::Deflate-OPT"></a><b>($d, $status) = new Compress::Raw::Zlib::Deflate( [OPT] ) </b></h2>

<p>Initialises a deflation object.</p>

<p>If you are familiar with the <i>zlib</i> library, it combines the features of the <i>zlib</i> functions <code>deflateInit</code>, <code>deflateInit2</code> and <code>deflateSetDictionary</code>.</p>

<p>If successful, it will return the initialised deflation object, <code>$d</code> and a <code>$status</code> of <code>Z_OK</code> in a list context. In scalar context it returns the deflation object, <code>$d</code>, only.</p>

<p>If not successful, the returned deflation object, <code>$d</code>, will be <i>undef</i> and <code>$status</code> will hold the a <i>zlib</i> error code.</p>

<p>The function optionally takes a number of named options specified as <code>Name =&gt; value</code> pairs. This allows individual options to be tailored without having to specify them all in the parameter list.</p>

<p>For backward compatibility, it is also possible to pass the parameters as a reference to a hash containing the name=&gt;value pairs.</p>

<p>Below is a list of the valid options:</p>

<dl>

<dt id="-Level"><a class="permalink" href="./Compress::Raw::Zlib.html#-Level">#</a><a id="Level"></a><b>-Level</b></dt>
<dd>

<p>Defines the compression level. Valid values are 0 through 9, <code>Z_NO_COMPRESSION</code>, <code>Z_BEST_SPEED</code>, <code>Z_BEST_COMPRESSION</code>, and <code>Z_DEFAULT_COMPRESSION</code>.</p>

<p>The default is <code>Z_DEFAULT_COMPRESSION</code>.</p>

</dd>
<dt id="-Method"><a class="permalink" href="./Compress::Raw::Zlib.html#-Method">#</a><a id="Method"></a><b>-Method</b></dt>
<dd>

<p>Defines the compression method. The only valid value at present (and the default) is <code>Z_DEFLATED</code>.</p>

</dd>
<dt id="-WindowBits"><a class="permalink" href="./Compress::Raw::Zlib.html#-WindowBits">#</a><a id="WindowBits"></a><b>-WindowBits</b></dt>
<dd>

<p>To compress an RFC 1950 data stream, set <code>WindowBits</code> to a positive number between 8 and 15.</p>

<p>To compress an RFC 1951 data stream, set <code>WindowBits</code> to <code>-MAX_WBITS</code>.</p>

<p>To compress an RFC 1952 data stream (i.e. gzip), set <code>WindowBits</code> to <code>WANT_GZIP</code>.</p>

<p>For a definition of the meaning and valid values for <code>WindowBits</code> refer to the <i>zlib</i> documentation for <i>deflateInit2</i>.</p>

<p>Defaults to <code>MAX_WBITS</code>.</p>

</dd>
<dt id="-MemLevel"><a class="permalink" href="./Compress::Raw::Zlib.html#-MemLevel">#</a><a id="MemLevel"></a><b>-MemLevel</b></dt>
<dd>

<p>For a definition of the meaning and valid values for <code>MemLevel</code> refer to the <i>zlib</i> documentation for <i>deflateInit2</i>.</p>

<p>Defaults to MAX_MEM_LEVEL.</p>

</dd>
<dt id="-Strategy"><a class="permalink" href="./Compress::Raw::Zlib.html#-Strategy">#</a><a id="Strategy"></a><b>-Strategy</b></dt>
<dd>

<p>Defines the strategy used to tune the compression. The valid values are <code>Z_DEFAULT_STRATEGY</code>, <code>Z_FILTERED</code>, <code>Z_RLE</code>, <code>Z_FIXED</code> and <code>Z_HUFFMAN_ONLY</code>.</p>

<p>The default is <code>Z_DEFAULT_STRATEGY</code>.</p>

</dd>
<dt id="-Dictionary"><a class="permalink" href="./Compress::Raw::Zlib.html#-Dictionary">#</a><a id="Dictionary"></a><b>-Dictionary</b></dt>
<dd>

<p>When a dictionary is specified <i>Compress::Raw::Zlib</i> will automatically call <code>deflateSetDictionary</code> directly after calling <code>deflateInit</code>. The Adler32 value for the dictionary can be obtained by calling the method <code>$d-&gt;dict_adler()</code>.</p>

<p>The default is no dictionary.</p>

</dd>
<dt id="-Bufsize"><a class="permalink" href="./Compress::Raw::Zlib.html#-Bufsize">#</a><a id="Bufsize"></a><b>-Bufsize</b></dt>
<dd>

<p>Sets the initial size for the output buffer used by the <code>$d-&gt;deflate</code> and <code>$d-&gt;flush</code> methods. If the buffer has to be reallocated to increase the size, it will grow in increments of <code>Bufsize</code>.</p>

<p>The default buffer size is 4096.</p>

</dd>
<dt id="-AppendOutput"><a class="permalink" href="./Compress::Raw::Zlib.html#-AppendOutput">#</a><a id="AppendOutput"></a><b>-AppendOutput</b></dt>
<dd>

<p>This option controls how data is written to the output buffer by the <code>$d-&gt;deflate</code> and <code>$d-&gt;flush</code> methods.</p>

<p>If the <code>AppendOutput</code> option is set to false, the output buffers in the <code>$d-&gt;deflate</code> and <code>$d-&gt;flush</code> methods will be truncated before uncompressed data is written to them.</p>

<p>If the option is set to true, uncompressed data will be appended to the output buffer in the <code>$d-&gt;deflate</code> and <code>$d-&gt;flush</code> methods.</p>

<p>This option defaults to false.</p>

</dd>
<dt id="-CRC32"><a class="permalink" href="./Compress::Raw::Zlib.html#-CRC32">#</a><a id="CRC32"></a><b>-CRC32</b></dt>
<dd>

<p>If set to true, a crc32 checksum of the uncompressed data will be calculated. Use the <code>$d-&gt;crc32</code> method to retrieve this value.</p>

<p>This option defaults to false.</p>

</dd>
<dt id="-ADLER32"><a class="permalink" href="./Compress::Raw::Zlib.html#-ADLER32">#</a><a id="ADLER32"></a><b>-ADLER32</b></dt>
<dd>

<p>If set to true, an adler32 checksum of the uncompressed data will be calculated. Use the <code>$d-&gt;adler32</code> method to retrieve this value.</p>

<p>This option defaults to false.</p>

</dd>
</dl>

<p>Here is an example of using the <code>Compress::Raw::Zlib::Deflate</code> optional parameter list to override the default buffer size and compression level. All other options will take their default values.</p>

<pre><code>my $d = new Compress::Raw::Zlib::Deflate ( -Bufsize =&gt; 300,
                                           -Level   =&gt; Z_BEST_SPEED ) ;</code></pre>

<h2 id="$status-=-$d-&gt;deflate($input,-$output)"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$d-%3Edeflate($input,-$output)">#</a><a id="status-d-deflate-input-output"></a><b>$status = $d-&gt;deflate($input, $output)</b></h2>

<p>Deflates the contents of <code>$input</code> and writes the compressed data to <code>$output</code>.</p>

<p>The <code>$input</code> and <code>$output</code> parameters can be either scalars or scalar references.</p>

<p>When finished, <code>$input</code> will be completely processed (assuming there were no errors). If the deflation was successful it writes the deflated data to <code>$output</code> and returns a status value of <code>Z_OK</code>.</p>

<p>On error, it returns a <i>zlib</i> error code.</p>

<p>If the <code>AppendOutput</code> option is set to true in the constructor for the <code>$d</code> object, the compressed data will be appended to <code>$output</code>. If it is false, <code>$output</code> will be truncated before any compressed data is written to it.</p>

<p><b>Note</b>: This method will not necessarily write compressed data to <code>$output</code> every time it is called. So do not assume that there has been an error if the contents of <code>$output</code> is empty on returning from this method. As long as the return code from the method is <code>Z_OK</code>, the deflate has succeeded.</p>

<h2 id="$status-=-$d-&gt;flush($output-[,-$flush_type])"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$d-%3Eflush($output-%5B,-$flush_type%5D)">#</a><a id="status-d-flush-output-flush_type"></a><b>$status = $d-&gt;flush($output [, $flush_type]) </b></h2>

<p>Typically used to finish the deflation. Any pending output will be written to <code>$output</code>.</p>

<p>Returns <code>Z_OK</code> if successful.</p>

<p>Note that flushing can seriously degrade the compression ratio, so it should only be used to terminate a decompression (using <code>Z_FINISH</code>) or when you want to create a <i>full flush point</i> (using <code>Z_FULL_FLUSH</code>).</p>

<p>By default the <code>flush_type</code> used is <code>Z_FINISH</code>. Other valid values for <code>flush_type</code> are <code>Z_NO_FLUSH</code>, <code>Z_PARTIAL_FLUSH</code>, <code>Z_SYNC_FLUSH</code> and <code>Z_FULL_FLUSH</code>. It is strongly recommended that you only set the <code>flush_type</code> parameter if you fully understand the implications of what it does. See the <code>zlib</code> documentation for details.</p>

<p>If the <code>AppendOutput</code> option is set to true in the constructor for the <code>$d</code> object, the compressed data will be appended to <code>$output</code>. If it is false, <code>$output</code> will be truncated before any compressed data is written to it.</p>

<h2 id="$status-=-$d-&gt;deflateReset()"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$d-%3EdeflateReset()">#</a><a id="status-d-deflateReset"></a><b>$status = $d-&gt;deflateReset() </b></h2>

<p>This method will reset the deflation object <code>$d</code>. It can be used when you are compressing multiple data streams and want to use the same object to compress each of them. It should only be used once the previous data stream has been flushed successfully, i.e. a call to <code>$d-&gt;flush(Z_FINISH)</code> has returned <code>Z_OK</code>.</p>

<p>Returns <code>Z_OK</code> if successful.</p>

<h2 id="$status-=-$d-&gt;deflateParams([OPT])"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$d-%3EdeflateParams(%5BOPT%5D)">#</a><a id="status-d-deflateParams-OPT"></a><b>$status = $d-&gt;deflateParams([OPT])</b></h2>

<p>Change settings for the deflate object <code>$d</code>.</p>

<p>The list of the valid options is shown below. Options not specified will remain unchanged.</p>

<dl>

<dt id="-Level1"><a class="permalink" href="./Compress::Raw::Zlib.html#-Level1">#</a><a id="Level1"></a><b>-Level</b></dt>
<dd>

<p>Defines the compression level. Valid values are 0 through 9, <code>Z_NO_COMPRESSION</code>, <code>Z_BEST_SPEED</code>, <code>Z_BEST_COMPRESSION</code>, and <code>Z_DEFAULT_COMPRESSION</code>.</p>

</dd>
<dt id="-Strategy1"><a class="permalink" href="./Compress::Raw::Zlib.html#-Strategy1">#</a><a id="Strategy1"></a><b>-Strategy</b></dt>
<dd>

<p>Defines the strategy used to tune the compression. The valid values are <code>Z_DEFAULT_STRATEGY</code>, <code>Z_FILTERED</code> and <code>Z_HUFFMAN_ONLY</code>.</p>

</dd>
<dt id="-BufSize"><a class="permalink" href="./Compress::Raw::Zlib.html#-BufSize">#</a><a id="BufSize"></a><b>-BufSize</b></dt>
<dd>

<p>Sets the initial size for the output buffer used by the <code>$d-&gt;deflate</code> and <code>$d-&gt;flush</code> methods. If the buffer has to be reallocated to increase the size, it will grow in increments of <code>Bufsize</code>.</p>

</dd>
</dl>

<h2 id="$status-=-$d-&gt;deflateTune($good_length,-$max_lazy,-$nice_length,-$max_chain)"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$d-%3EdeflateTune($good_length,-$max_lazy,-$nice_length,-$max_chain)">#</a><a id="status-d-deflateTune-good_length-max_lazy-nice_length-max_chain"></a><b>$status = $d-&gt;deflateTune($good_length, $max_lazy, $nice_length, $max_chain)</b></h2>

<p>Tune the internal settings for the deflate object <code>$d</code>. This option is only available if you are running zlib 1.2.2.3 or better.</p>

<p>Refer to the documentation in zlib.h for instructions on how to fly <code>deflateTune</code>.</p>

<h2 id="$d-&gt;dict_adler()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Edict_adler()">#</a><a id="dict_adler"></a><a id="d-dict_adler"></a><b>$d-&gt;dict_adler()</b></h2>

<p>Returns the adler32 value for the dictionary.</p>

<h2 id="$d-&gt;crc32()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Ecrc32()">#</a><a id="crc32"></a><a id="d-crc32"></a><b>$d-&gt;crc32()</b></h2>

<p>Returns the crc32 value for the uncompressed data to date.</p>

<p>If the <code>CRC32</code> option is not enabled in the constructor for this object, this method will always return 0;</p>

<h2 id="$d-&gt;adler32()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Eadler32()">#</a><a id="adler32"></a><a id="d-adler32"></a><b>$d-&gt;adler32()</b></h2>

<p>Returns the adler32 value for the uncompressed data to date.</p>

<h2 id="$d-&gt;msg()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Emsg()">#</a><a id="msg"></a><a id="d-msg"></a><b>$d-&gt;msg()</b></h2>

<p>Returns the last error message generated by zlib.</p>

<h2 id="$d-&gt;total_in()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Etotal_in()">#</a><a id="total_in"></a><a id="d-total_in"></a><b>$d-&gt;total_in()</b></h2>

<p>Returns the total number of bytes uncompressed bytes input to deflate.</p>

<h2 id="$d-&gt;total_out()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Etotal_out()">#</a><a id="total_out"></a><a id="d-total_out"></a><b>$d-&gt;total_out()</b></h2>

<p>Returns the total number of compressed bytes output from deflate.</p>

<h2 id="$d-&gt;get_Strategy()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Eget_Strategy()">#</a><a id="get_Strategy"></a><a id="d-get_Strategy"></a><b>$d-&gt;get_Strategy()</b></h2>

<p>Returns the deflation strategy currently used. Valid values are <code>Z_DEFAULT_STRATEGY</code>, <code>Z_FILTERED</code> and <code>Z_HUFFMAN_ONLY</code>.</p>

<h2 id="$d-&gt;get_Level()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Eget_Level()">#</a><a id="get_Level"></a><a id="d-get_Level"></a><b>$d-&gt;get_Level()</b></h2>

<p>Returns the compression level being used.</p>

<h2 id="$d-&gt;get_BufSize()"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Eget_BufSize()">#</a><a id="get_BufSize"></a><a id="d-get_BufSize"></a><b>$d-&gt;get_BufSize()</b></h2>

<p>Returns the buffer size used to carry out the compression.</p>

<h2 id="Example"><a class="permalink" href="./Compress::Raw::Zlib.html#Example">#</a>Example</h2>

<p>Here is a trivial example of using <code>deflate</code>. It simply reads standard input, deflates it and writes it to standard output.</p>

<pre><code>use strict ;
use warnings ;

use Compress::Raw::Zlib ;

binmode STDIN;
binmode STDOUT;
my $x = new Compress::Raw::Zlib::Deflate
   or die &quot;Cannot create a deflation stream\n&quot; ;

my ($output, $status) ;
while (&lt;&gt;)
{
    $status = $x-&gt;deflate($_, $output) ;

    $status == Z_OK
        or die &quot;deflation failed\n&quot; ;

    print $output ;
}

$status = $x-&gt;flush($output) ;

$status == Z_OK
    or die &quot;deflation failed\n&quot; ;

print $output ;</code></pre>

<h1 id="Compress::Raw::Zlib::Inflate"><a class="permalink" href="./Compress::Raw::Zlib.html#Compress::Raw::Zlib::Inflate">#</a><a id="Compress1"></a>Compress::Raw::Zlib::Inflate</h1>

<p>This section defines an interface that allows in-memory uncompression using the <i>inflate</i> interface provided by zlib.</p>

<p>Here is a definition of the interface:</p>

<h2 id="($i,-$status)-=-new-Compress::Raw::Zlib::Inflate(-[OPT]-)"><a class="permalink" href="./Compress::Raw::Zlib.html#($i,-$status)-=-new-Compress::Raw::Zlib::Inflate(-%5BOPT%5D-)">#</a><a id="i-status-new-Compress::Raw::Zlib::Inflate-OPT"></a><b> ($i, $status) = new Compress::Raw::Zlib::Inflate( [OPT] ) </b></h2>

<p>Initialises an inflation object.</p>

<p>In a list context it returns the inflation object, <code>$i</code>, and the <i>zlib</i> status code (<code>$status</code>). In a scalar context it returns the inflation object only.</p>

<p>If successful, <code>$i</code> will hold the inflation object and <code>$status</code> will be <code>Z_OK</code>.</p>

<p>If not successful, <code>$i</code> will be <i>undef</i> and <code>$status</code> will hold the <i>zlib</i> error code.</p>

<p>The function optionally takes a number of named options specified as <code>-Name =&gt; value</code> pairs. This allows individual options to be tailored without having to specify them all in the parameter list.</p>

<p>For backward compatibility, it is also possible to pass the parameters as a reference to a hash containing the <code>name=&gt;value</code> pairs.</p>

<p>Here is a list of the valid options:</p>

<dl>

<dt id="-WindowBits1"><a class="permalink" href="./Compress::Raw::Zlib.html#-WindowBits1">#</a><a id="WindowBits1"></a><b>-WindowBits</b></dt>
<dd>

<p>To uncompress an RFC 1950 data stream, set <code>WindowBits</code> to a positive number between 8 and 15.</p>

<p>To uncompress an RFC 1951 data stream, set <code>WindowBits</code> to <code>-MAX_WBITS</code>.</p>

<p>To uncompress an RFC 1952 data stream (i.e. gzip), set <code>WindowBits</code> to <code>WANT_GZIP</code>.</p>

<p>To auto-detect and uncompress an RFC 1950 or RFC 1952 data stream (i.e. gzip), set <code>WindowBits</code> to <code>WANT_GZIP_OR_ZLIB</code>.</p>

<p>For a full definition of the meaning and valid values for <code>WindowBits</code> refer to the <i>zlib</i> documentation for <i>inflateInit2</i>.</p>

<p>Defaults to <code>MAX_WBITS</code>.</p>

</dd>
<dt id="-Bufsize1"><a class="permalink" href="./Compress::Raw::Zlib.html#-Bufsize1">#</a><a id="Bufsize1"></a><b>-Bufsize</b></dt>
<dd>

<p>Sets the initial size for the output buffer used by the <code>$i-&gt;inflate</code> method. If the output buffer in this method has to be reallocated to increase the size, it will grow in increments of <code>Bufsize</code>.</p>

<p>Default is 4096.</p>

</dd>
<dt id="-Dictionary1"><a class="permalink" href="./Compress::Raw::Zlib.html#-Dictionary1">#</a><a id="Dictionary1"></a><b>-Dictionary</b></dt>
<dd>

<p>The default is no dictionary.</p>

</dd>
<dt id="-AppendOutput1"><a class="permalink" href="./Compress::Raw::Zlib.html#-AppendOutput1">#</a><a id="AppendOutput1"></a><b>-AppendOutput</b></dt>
<dd>

<p>This option controls how data is written to the output buffer by the <code>$i-&gt;inflate</code> method.</p>

<p>If the option is set to false, the output buffer in the <code>$i-&gt;inflate</code> method will be truncated before uncompressed data is written to it.</p>

<p>If the option is set to true, uncompressed data will be appended to the output buffer by the <code>$i-&gt;inflate</code> method.</p>

<p>This option defaults to false.</p>

</dd>
<dt id="-CRC321"><a class="permalink" href="./Compress::Raw::Zlib.html#-CRC321">#</a><a id="CRC321"></a><b>-CRC32</b></dt>
<dd>

<p>If set to true, a crc32 checksum of the uncompressed data will be calculated. Use the <code>$i-&gt;crc32</code> method to retrieve this value.</p>

<p>This option defaults to false.</p>

</dd>
<dt id="-ADLER321"><a class="permalink" href="./Compress::Raw::Zlib.html#-ADLER321">#</a><a id="ADLER321"></a><b>-ADLER32</b></dt>
<dd>

<p>If set to true, an adler32 checksum of the uncompressed data will be calculated. Use the <code>$i-&gt;adler32</code> method to retrieve this value.</p>

<p>This option defaults to false.</p>

</dd>
<dt id="-ConsumeInput"><a class="permalink" href="./Compress::Raw::Zlib.html#-ConsumeInput">#</a><a id="ConsumeInput"></a><b>-ConsumeInput</b></dt>
<dd>

<p>If set to true, this option will remove compressed data from the input buffer of the <code>$i-&gt;inflate</code> method as the inflate progresses.</p>

<p>This option can be useful when you are processing compressed data that is embedded in another file/buffer. In this case the data that immediately follows the compressed stream will be left in the input buffer.</p>

<p>This option defaults to true.</p>

</dd>
<dt id="-LimitOutput"><a class="permalink" href="./Compress::Raw::Zlib.html#-LimitOutput">#</a><a id="LimitOutput"></a><b>-LimitOutput</b></dt>
<dd>

<p>The <code>LimitOutput</code> option changes the behavior of the <code>$i-&gt;inflate</code> method so that the amount of memory used by the output buffer can be limited.</p>

<p>When <code>LimitOutput</code> is used the size of the output buffer used will either be the value of the <code>Bufsize</code> option or the amount of memory already allocated to <code>$output</code>, whichever is larger. Predicting the output size available is tricky, so don&#39;t rely on getting an exact output buffer size.</p>

<p>When <code>LimitOutout</code> is not specified <code>$i-&gt;inflate</code> will use as much memory as it takes to write all the uncompressed data it creates by uncompressing the input buffer.</p>

<p>If <code>LimitOutput</code> is enabled, the <code>ConsumeInput</code> option will also be enabled.</p>

<p>This option defaults to false.</p>

<p>See <a href="./Compress::Raw::Zlib.html#The-LimitOutput-option">&quot;The LimitOutput option&quot;</a> for a discussion on why <code>LimitOutput</code> is needed and how to use it.</p>

</dd>
</dl>

<p>Here is an example of using an optional parameter to override the default buffer size.</p>

<pre><code>my ($i, $status) = new Compress::Raw::Zlib::Inflate( -Bufsize =&gt; 300 ) ;</code></pre>

<h2 id="$status-=-$i-&gt;inflate($input,-$output-[,$eof])"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$i-%3Einflate($input,-$output-%5B,$eof%5D)">#</a><a id="status-i-inflate-input-output-eof"></a><b> $status = $i-&gt;inflate($input, $output [,$eof]) </b></h2>

<p>Inflates the complete contents of <code>$input</code> and writes the uncompressed data to <code>$output</code>. The <code>$input</code> and <code>$output</code> parameters can either be scalars or scalar references.</p>

<p>Returns <code>Z_OK</code> if successful and <code>Z_STREAM_END</code> if the end of the compressed data has been successfully reached.</p>

<p>If not successful <code>$status</code> will hold the <i>zlib</i> error code.</p>

<p>If the <code>ConsumeInput</code> option has been set to true when the <code>Compress::Raw::Zlib::Inflate</code> object is created, the <code>$input</code> parameter is modified by <code>inflate</code>. On completion it will contain what remains of the input buffer after inflation. In practice, this means that when the return status is <code>Z_OK</code> the <code>$input</code> parameter will contain an empty string, and when the return status is <code>Z_STREAM_END</code> the <code>$input</code> parameter will contains what (if anything) was stored in the input buffer after the deflated data stream.</p>

<p>This feature is useful when processing a file format that encapsulates a compressed data stream (e.g. gzip, zip) and there is useful data immediately after the deflation stream.</p>

<p>If the <code>AppendOutput</code> option is set to true in the constructor for this object, the uncompressed data will be appended to <code>$output</code>. If it is false, <code>$output</code> will be truncated before any uncompressed data is written to it.</p>

<p>The <code>$eof</code> parameter needs a bit of explanation.</p>

<p>Prior to version 1.2.0, zlib assumed that there was at least one trailing byte immediately after the compressed data stream when it was carrying out decompression. This normally isn&#39;t a problem because the majority of zlib applications guarantee that there will be data directly after the compressed data stream. For example, both gzip (RFC 1950) and zip both define trailing data that follows the compressed data stream.</p>

<p>The <code>$eof</code> parameter only needs to be used if <b>all</b> of the following conditions apply</p>

<ol>

<li><p>You are either using a copy of zlib that is older than version 1.2.0 or you want your application code to be able to run with as many different versions of zlib as possible.</p>

</li>
<li><p>You have set the <code>WindowBits</code> parameter to <code>-MAX_WBITS</code> in the constructor for this object, i.e. you are uncompressing a raw deflated data stream (RFC 1951).</p>

</li>
<li><p>There is no data immediately after the compressed data stream.</p>

</li>
</ol>

<p>If <b>all</b> of these are the case, then you need to set the <code>$eof</code> parameter to true on the final call (and only the final call) to <code>$i-&gt;inflate</code>.</p>

<p>If you have built this module with zlib &gt;= 1.2.0, the <code>$eof</code> parameter is ignored. You can still set it if you want, but it won&#39;t be used behind the scenes.</p>

<h2 id="$status-=-$i-&gt;inflateSync($input)"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$i-%3EinflateSync($input)">#</a><a id="status-i-inflateSync-input"></a><b>$status = $i-&gt;inflateSync($input)</b></h2>

<p>This method can be used to attempt to recover good data from a compressed data stream that is partially corrupt. It scans <code>$input</code> until it reaches either a <i>full flush point</i> or the end of the buffer.</p>

<p>If a <i>full flush point</i> is found, <code>Z_OK</code> is returned and <code>$input</code> will be have all data up to the flush point removed. This data can then be passed to the <code>$i-&gt;inflate</code> method to be uncompressed.</p>

<p>Any other return code means that a flush point was not found. If more data is available, <code>inflateSync</code> can be called repeatedly with more compressed data until the flush point is found.</p>

<p>Note <i>full flush points</i> are not present by default in compressed data streams. They must have been added explicitly when the data stream was created by calling <code>Compress::Deflate::flush</code> with <code>Z_FULL_FLUSH</code>.</p>

<h2 id="$status-=-$i-&gt;inflateReset()"><a class="permalink" href="./Compress::Raw::Zlib.html#$status-=-$i-%3EinflateReset()">#</a><a id="status-i-inflateReset"></a><b>$status = $i-&gt;inflateReset() </b></h2>

<p>This method will reset the inflation object <code>$i</code>. It can be used when you are uncompressing multiple data streams and want to use the same object to uncompress each of them.</p>

<p>Returns <code>Z_OK</code> if successful.</p>

<h2 id="$i-&gt;dict_adler()"><a class="permalink" href="./Compress::Raw::Zlib.html#$i-%3Edict_adler()">#</a><a id="dict_adler1"></a><a id="i-dict_adler"></a><b>$i-&gt;dict_adler()</b></h2>

<p>Returns the adler32 value for the dictionary.</p>

<h2 id="$i-&gt;crc32()"><a class="permalink" href="./Compress::Raw::Zlib.html#$i-%3Ecrc32()">#</a><a id="crc321"></a><a id="i-crc32"></a><b>$i-&gt;crc32()</b></h2>

<p>Returns the crc32 value for the uncompressed data to date.</p>

<p>If the <code>CRC32</code> option is not enabled in the constructor for this object, this method will always return 0;</p>

<h2 id="$i-&gt;adler32()"><a class="permalink" href="./Compress::Raw::Zlib.html#$i-%3Eadler32()">#</a><a id="adler321"></a><a id="i-adler32"></a><b>$i-&gt;adler32()</b></h2>

<p>Returns the adler32 value for the uncompressed data to date.</p>

<p>If the <code>ADLER32</code> option is not enabled in the constructor for this object, this method will always return 0;</p>

<h2 id="$i-&gt;msg()"><a class="permalink" href="./Compress::Raw::Zlib.html#$i-%3Emsg()">#</a><a id="msg1"></a><a id="i-msg"></a><b>$i-&gt;msg()</b></h2>

<p>Returns the last error message generated by zlib.</p>

<h2 id="$i-&gt;total_in()"><a class="permalink" href="./Compress::Raw::Zlib.html#$i-%3Etotal_in()">#</a><a id="total_in1"></a><a id="i-total_in"></a><b>$i-&gt;total_in()</b></h2>

<p>Returns the total number of bytes compressed bytes input to inflate.</p>

<h2 id="$i-&gt;total_out()"><a class="permalink" href="./Compress::Raw::Zlib.html#$i-%3Etotal_out()">#</a><a id="total_out1"></a><a id="i-total_out"></a><b>$i-&gt;total_out()</b></h2>

<p>Returns the total number of uncompressed bytes output from inflate.</p>

<h2 id="$d-&gt;get_BufSize()1"><a class="permalink" href="./Compress::Raw::Zlib.html#$d-%3Eget_BufSize()1">#</a><a id="get_BufSize1"></a><a id="d-get_BufSize1"></a><b>$d-&gt;get_BufSize()</b></h2>

<p>Returns the buffer size used to carry out the decompression.</p>

<h2 id="Examples"><a class="permalink" href="./Compress::Raw::Zlib.html#Examples">#</a>Examples</h2>

<p>Here is an example of using <code>inflate</code>.</p>

<pre><code>use strict ;
use warnings ;

use Compress::Raw::Zlib;

my $x = new Compress::Raw::Zlib::Inflate()
   or die &quot;Cannot create a inflation stream\n&quot; ;

my $input = &#39;&#39; ;
binmode STDIN;
binmode STDOUT;

my ($output, $status) ;
while (read(STDIN, $input, 4096))
{
    $status = $x-&gt;inflate($input, $output) ;

    print $output ;

    last if $status != Z_OK ;
}

die &quot;inflation failed\n&quot;
    unless $status == Z_STREAM_END ;</code></pre>

<p>The next example show how to use the <code>LimitOutput</code> option. Notice the use of two nested loops in this case. The outer loop reads the data from the input source - STDIN and the inner loop repeatedly calls <code>inflate</code> until <code>$input</code> is exhausted, we get an error, or the end of the stream is reached. One point worth remembering is by using the <code>LimitOutput</code> option you also get <code>ConsumeInput</code> set as well - this makes the code below much simpler.</p>

<pre><code>  use strict ;
  use warnings ;

  use Compress::Raw::Zlib;

  my $x = new Compress::Raw::Zlib::Inflate(LimitOutput =&gt; 1)
     or die &quot;Cannot create a inflation stream\n&quot; ;

  my $input = &#39;&#39; ;
  binmode STDIN;
  binmode STDOUT;

  my ($output, $status) ;

OUTER:
  while (read(STDIN, $input, 4096))
  {
      do
      {
          $status = $x-&gt;inflate($input, $output) ;

          print $output ;

          last OUTER
              unless $status == Z_OK || $status == Z_BUF_ERROR ;
      }
      while ($status == Z_OK &amp;&amp; length $input);
  }

  die &quot;inflation failed\n&quot;
      unless $status == Z_STREAM_END ;</code></pre>

<h1 id="CHECKSUM-FUNCTIONS"><a class="permalink" href="./Compress::Raw::Zlib.html#CHECKSUM-FUNCTIONS">#</a><a id="CHECKSUM"></a>CHECKSUM FUNCTIONS</h1>

<p>Two functions are provided by <i>zlib</i> to calculate checksums. For the Perl interface, the order of the two parameters in both functions has been reversed. This allows both running checksums and one off calculations to be done.</p>

<pre><code>$crc = adler32($buffer [,$crc]) ;
$crc = crc32($buffer [,$crc]) ;</code></pre>

<p>The buffer parameters can either be a scalar or a scalar reference.</p>

<p>If the $crc parameters is <code>undef</code>, the crc value will be reset.</p>

<p>If you have built this module with zlib 1.2.3 or better, two more CRC-related functions are available.</p>

<pre><code>$crc = crc32_combine($crc1, $crc2, $len2);
$adler = adler32_combine($adler1, $adler2, $len2);</code></pre>

<p>These functions allow checksums to be merged. Refer to the <i>zlib</i> documentation for more details.</p>

<h1 id="Misc"><a class="permalink" href="./Compress::Raw::Zlib.html#Misc">#</a>Misc</h1>

<h2 id="my-$version-=-Compress::Raw::Zlib::zlib_version();"><a class="permalink" href="./Compress::Raw::Zlib.html#my-$version-=-Compress::Raw::Zlib::zlib_version();">#</a><a id="my"></a><a id="my-version-Compress::Raw::Zlib::zlib_version"></a>my $version = Compress::Raw::Zlib::zlib_version();</h2>

<p>Returns the version of the zlib library.</p>

<h2 id="my-$flags-=-Compress::Raw::Zlib::zlibCompileFlags();"><a class="permalink" href="./Compress::Raw::Zlib.html#my-$flags-=-Compress::Raw::Zlib::zlibCompileFlags();">#</a><a id="my1"></a><a id="my-flags-Compress::Raw::Zlib::zlibCompileFlags"></a>my $flags = Compress::Raw::Zlib::zlibCompileFlags();</h2>

<p>Returns the flags indicating compile-time options that were used to build the zlib library. See the zlib documentation for a description of the flags returned by <code>zlibCompileFlags</code>.</p>

<p>Note that when the zlib sources are built along with this module the <code>sprintf</code> flags (bits 24, 25 and 26) should be ignored.</p>

<p>If you are using zlib 1.2.0 or older, <code>zlibCompileFlags</code> will return 0.</p>

<h1 id="The-LimitOutput-option."><a class="permalink" href="./Compress::Raw::Zlib.html#The-LimitOutput-option.">#</a><a id="The"></a><a id="The-LimitOutput-option"></a>The LimitOutput option.</h1>

<p>By default <code>$i-&gt;inflate($input, $output)</code> will uncompress <i>all</i> data in <code>$input</code> and write <i>all</i> of the uncompressed data it has generated to <code>$output</code>. This makes the interface to <code>inflate</code> much simpler - if the method has uncompressed <code>$input</code> successfully <i>all</i> compressed data in <code>$input</code> will have been dealt with. So if you are reading from an input source and uncompressing as you go the code will look something like this</p>

<pre><code>use strict ;
use warnings ;

use Compress::Raw::Zlib;

my $x = new Compress::Raw::Zlib::Inflate()
   or die &quot;Cannot create a inflation stream\n&quot; ;

my $input = &#39;&#39; ;

my ($output, $status) ;
while (read(STDIN, $input, 4096))
{
    $status = $x-&gt;inflate($input, $output) ;

    print $output ;

    last if $status != Z_OK ;
}

die &quot;inflation failed\n&quot;
    unless $status == Z_STREAM_END ;</code></pre>

<p>The points to note are</p>

<ul>

<li><p>The main processing loop in the code handles reading of compressed data from STDIN.</p>

</li>
<li><p>The status code returned from <code>inflate</code> will only trigger termination of the main processing loop if it isn&#39;t <code>Z_OK</code>. When <code>LimitOutput</code> has not been used the <code>Z_OK</code> status means that the end of the compressed data stream has been reached or there has been an error in uncompression.</p>

</li>
<li><p>After the call to <code>inflate</code> <i>all</i> of the uncompressed data in <code>$input</code> will have been processed. This means the subsequent call to <code>read</code> can overwrite it&#39;s contents without any problem.</p>

</li>
</ul>

<p>For most use-cases the behavior described above is acceptable (this module and it&#39;s predecessor, <code>Compress::Zlib</code>, have used it for over 10 years without an issue), but in a few very specific use-cases the amount of memory required for <code>$output</code> can prohibitively large. For example, if the compressed data stream contains the same pattern repeated thousands of times, a relatively small compressed data stream can uncompress into hundreds of megabytes. Remember <code>inflate</code> will keep allocating memory until <i>all</i> the uncompressed data has been written to the output buffer - the size of <code>$output</code> is unbounded.</p>

<p>The <code>LimitOutput</code> option is designed to help with this use-case.</p>

<p>The main difference in your code when using <code>LimitOutput</code> is having to deal with cases where the <code>$input</code> parameter still contains some uncompressed data that <code>inflate</code> hasn&#39;t processed yet. The status code returned from <code>inflate</code> will be <code>Z_OK</code> if uncompression took place and <code>Z_BUF_ERROR</code> if the output buffer is full.</p>

<p>Below is typical code that shows how to use <code>LimitOutput</code>.</p>

<pre><code>  use strict ;
  use warnings ;

  use Compress::Raw::Zlib;

  my $x = new Compress::Raw::Zlib::Inflate(LimitOutput =&gt; 1)
     or die &quot;Cannot create a inflation stream\n&quot; ;

  my $input = &#39;&#39; ;
  binmode STDIN;
  binmode STDOUT;

  my ($output, $status) ;

OUTER:
  while (read(STDIN, $input, 4096))
  {
      do
      {
          $status = $x-&gt;inflate($input, $output) ;

          print $output ;

          last OUTER
              unless $status == Z_OK || $status == Z_BUF_ERROR ;
      }
      while ($status == Z_OK &amp;&amp; length $input);
  }

  die &quot;inflation failed\n&quot;
      unless $status == Z_STREAM_END ;</code></pre>

<p>Points to note this time:</p>

<ul>

<li><p>There are now two nested loops in the code: the outer loop for reading the compressed data from STDIN, as before; and the inner loop to carry out the uncompression.</p>

</li>
<li><p>There are two exit points from the inner uncompression loop.</p>

<p>Firstly when <code>inflate</code> has returned a status other than <code>Z_OK</code> or <code>Z_BUF_ERROR</code>. This means that either the end of the compressed data stream has been reached (<code>Z_STREAM_END</code>) or there is an error in the compressed data. In either of these cases there is no point in continuing with reading the compressed data, so both loops are terminated.</p>

<p>The second exit point tests if there is any data left in the input buffer, <code>$input</code> - remember that the <code>ConsumeInput</code> option is automatically enabled when <code>LimitOutput</code> is used. When the input buffer has been exhausted, the outer loop can run again and overwrite a now empty <code>$input</code>.</p>

</li>
</ul>

<h1 id="ACCESSING-ZIP-FILES"><a class="permalink" href="./Compress::Raw::Zlib.html#ACCESSING-ZIP-FILES">#</a><a id="ACCESSING"></a>ACCESSING ZIP FILES</h1>

<p>Although it is possible (with some effort on your part) to use this module to access .zip files, there are other perl modules available that will do all the hard work for you. Check out <code>Archive::Zip</code>, <code>Archive::Zip::SimpleZip</code>, <code>IO::Compress::Zip</code> and <code>IO::Uncompress::Unzip</code>.</p>

<h1 id="FAQ"><a class="permalink" href="./Compress::Raw::Zlib.html#FAQ">#</a>FAQ</h1>

<h2 id="Compatibility-with-Unix-compress/uncompress."><a class="permalink" href="./Compress::Raw::Zlib.html#Compatibility-with-Unix-compress/uncompress.">#</a><a id="Compatibility"></a><a id="Compatibility-with-Unix-compress-uncompress"></a>Compatibility with Unix compress/uncompress.</h2>

<p>This module is not compatible with Unix <code>compress</code>.</p>

<p>If you have the <code>uncompress</code> program available, you can use this to read compressed files</p>

<pre><code>open F, &quot;uncompress -c $filename |&quot;;
while (&lt;F&gt;)
{
    ...</code></pre>

<p>Alternatively, if you have the <code>gunzip</code> program available, you can use this to read compressed files</p>

<pre><code>open F, &quot;gunzip -c $filename |&quot;;
while (&lt;F&gt;)
{
    ...</code></pre>

<p>and this to write compress files, if you have the <code>compress</code> program available</p>

<pre><code>open F, &quot;| compress -c $filename &quot;;
print F &quot;data&quot;;
...
close F ;</code></pre>

<h2 id="Accessing-.tar.Z-files"><a class="permalink" href="./Compress::Raw::Zlib.html#Accessing-.tar.Z-files">#</a><a id="Accessing"></a>Accessing .tar.Z files</h2>

<p>See previous FAQ item.</p>

<p>If the <code>Archive::Tar</code> module is installed and either the <code>uncompress</code> or <code>gunzip</code> programs are available, you can use one of these workarounds to read <code>.tar.Z</code> files.</p>

<p>Firstly with <code>uncompress</code></p>

<pre><code>use strict;
use warnings;
use Archive::Tar;

open F, &quot;uncompress -c $filename |&quot;;
my $tar = Archive::Tar-&gt;new(*F);
...</code></pre>

<p>and this with <code>gunzip</code></p>

<pre><code>use strict;
use warnings;
use Archive::Tar;

open F, &quot;gunzip -c $filename |&quot;;
my $tar = Archive::Tar-&gt;new(*F);
...</code></pre>

<p>Similarly, if the <code>compress</code> program is available, you can use this to write a <code>.tar.Z</code> file</p>

<pre><code>use strict;
use warnings;
use Archive::Tar;
use IO::File;

my $fh = new IO::File &quot;| compress -c &gt;$filename&quot;;
my $tar = Archive::Tar-&gt;new();
...
$tar-&gt;write($fh);
$fh-&gt;close ;</code></pre>

<h2 id="Zlib-Library-Version-Support"><a class="permalink" href="./Compress::Raw::Zlib.html#Zlib-Library-Version-Support">#</a><a id="Zlib"></a>Zlib Library Version Support</h2>

<p>By default <code>Compress::Raw::Zlib</code> will build with a private copy of version 1.2.5 of the zlib library. (See the <i>README</i> file for details of how to override this behaviour)</p>

<p>If you decide to use a different version of the zlib library, you need to be aware of the following issues</p>

<ul>

<li><p>First off, you must have zlib 1.0.5 or better.</p>

</li>
<li><p>You need to have zlib 1.2.1 or better if you want to use the <code>-Merge</code> option with <code>IO::Compress::Gzip</code>, <code>IO::Compress::Deflate</code> and <code>IO::Compress::RawDeflate</code>.</p>

</li>
</ul>

<h1 id="CONSTANTS"><a class="permalink" href="./Compress::Raw::Zlib.html#CONSTANTS">#</a>CONSTANTS</h1>

<p>All the <i>zlib</i> constants are automatically imported when you make use of <i>Compress::Raw::Zlib</i>.</p>

<h1 id="SUPPORT"><a class="permalink" href="./Compress::Raw::Zlib.html#SUPPORT">#</a>SUPPORT</h1>

<p>General feedback/questions/bug reports should be sent to <a href="https://github.com/pmqs/Compress-Raw-Zlib/issues">https://github.com/pmqs/Compress-Raw-Zlib/issues</a> (preferred) or <a href="https://rt.cpan.org/Public/Dist/Display.html?Name=Compress-Raw-Zlib">https://rt.cpan.org/Public/Dist/Display.html?Name=Compress-Raw-Zlib</a>.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="./Compress::Raw::Zlib.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="./Compress::Zlib.html">Compress::Zlib</a>, <a href="./IO::Compress::Gzip.html">IO::Compress::Gzip</a>, <a href="./IO::Uncompress::Gunzip.html">IO::Uncompress::Gunzip</a>, <a href="./IO::Compress::Deflate.html">IO::Compress::Deflate</a>, <a href="./IO::Uncompress::Inflate.html">IO::Uncompress::Inflate</a>, <a href="./IO::Compress::RawDeflate.html">IO::Compress::RawDeflate</a>, <a href="./IO::Uncompress::RawInflate.html">IO::Uncompress::RawInflate</a>, <a href="./IO::Compress::Bzip2.html">IO::Compress::Bzip2</a>, <a href="./IO::Uncompress::Bunzip2.html">IO::Uncompress::Bunzip2</a>, <a href="./IO::Compress::Lzma.html">IO::Compress::Lzma</a>, <a href="./IO::Uncompress::UnLzma.html">IO::Uncompress::UnLzma</a>, <a href="./IO::Compress::Xz.html">IO::Compress::Xz</a>, <a href="./IO::Uncompress::UnXz.html">IO::Uncompress::UnXz</a>, <a href="./IO::Compress::Lzip.html">IO::Compress::Lzip</a>, <a href="./IO::Uncompress::UnLzip.html">IO::Uncompress::UnLzip</a>, <a href="./IO::Compress::Lzop.html">IO::Compress::Lzop</a>, <a href="./IO::Uncompress::UnLzop.html">IO::Uncompress::UnLzop</a>, <a href="./IO::Compress::Lzf.html">IO::Compress::Lzf</a>, <a href="./IO::Uncompress::UnLzf.html">IO::Uncompress::UnLzf</a>, <a href="./IO::Compress::Zstd.html">IO::Compress::Zstd</a>, <a href="./IO::Uncompress::UnZstd.html">IO::Uncompress::UnZstd</a>, <a href="./IO::Uncompress::AnyInflate.html">IO::Uncompress::AnyInflate</a>, <a href="./IO::Uncompress::AnyUncompress.html">IO::Uncompress::AnyUncompress</a></p>

<p><a href="./IO::Compress::FAQ.html">IO::Compress::FAQ</a></p>

<p><a href="./File::GlobMapper.html">File::GlobMapper</a>, <a href="./Archive::Zip.html">Archive::Zip</a>, <a href="./Archive::Tar.html">Archive::Tar</a>, <a href="./IO::Zlib.html">IO::Zlib</a></p>

<p>For RFC 1950, 1951 and 1952 see <a href="http://www.faqs.org/rfcs/rfc1950.html">http://www.faqs.org/rfcs/rfc1950.html</a>, <a href="http://www.faqs.org/rfcs/rfc1951.html">http://www.faqs.org/rfcs/rfc1951.html</a> and <a href="http://www.faqs.org/rfcs/rfc1952.html">http://www.faqs.org/rfcs/rfc1952.html</a></p>

<p>The <i>zlib</i> compression library was written by Jean-loup Gailly <code>gzip@prep.ai.mit.edu</code> and Mark Adler <code>madler@alumni.caltech.edu</code>.</p>

<p>The primary site for the <i>zlib</i> compression library is <a href="http://www.zlib.org">http://www.zlib.org</a>.</p>

<p>The primary site for gzip is <a href="http://www.gzip.org">http://www.gzip.org</a>.</p>

<h1 id="AUTHOR"><a class="permalink" href="./Compress::Raw::Zlib.html#AUTHOR">#</a>AUTHOR</h1>

<p>This module was written by Paul Marquess, <code>pmqs@cpan.org</code>.</p>

<h1 id="MODIFICATION-HISTORY"><a class="permalink" href="./Compress::Raw::Zlib.html#MODIFICATION-HISTORY">#</a><a id="MODIFICATION"></a>MODIFICATION HISTORY</h1>

<p>See the Changes file.</p>

<h1 id="COPYRIGHT-AND-LICENSE"><a class="permalink" href="./Compress::Raw::Zlib.html#COPYRIGHT-AND-LICENSE">#</a><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1>

<p>Copyright (c) 2005-2021 Paul Marquess. All rights reserved.</p>

<p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
